package com.emp.test.springboottest.domain.dao;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.yhd.object.order.Order;

@Repository(value = "orderDao")
public class OrderDao {
	
	@Autowired
	NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	
	public OrderDao() {
		super();
	}

	@Transactional
	public int[] batchInsert(List<Order> orders){
		if(null == orders) return null;

		SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(orders.toArray());
        int[] updateCounts = namedParameterJdbcTemplate.batchUpdate(
                "REPLACE into yhd_order(orderId,uptime) values(:orderId,'"+ DateFormatUtils.ISO_DATETIME_FORMAT.format(new Date()) + "')",
                batch);
        return updateCounts;
	}
	
	@Transactional
	public void insert(Order order){
		
	}
	
}
